package Eyjafjalla.helper;

import Eyjafjalla.modcore.EyjafjallaMod;
import basemod.BaseMod;
import basemod.ModLabeledToggleButton;
import basemod.ModPanel;
import com.badlogic.gdx.graphics.Texture;
import com.evacipated.cardcrawl.modthespire.lib.SpireConfig;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.helpers.FontHelper;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.localization.UIStrings;

import java.io.IOException;
import java.util.Properties;

public class ModConfig {
    private static final String ENABLED_ALL_DOLLY = "eyjafjalla:ENABLED_ALL_DOLLY";
    public static boolean enable = false;
    public static SpireConfig config = null;
    private static Properties defaultSetting = new Properties();
    private static ModPanel settingsPanel;

    public static void initModSettings(){
        defaultSetting.setProperty(ENABLED_ALL_DOLLY,String.valueOf(enable));
        try {
            config = new SpireConfig("Eyjafjalla_FimmlpS","Common",defaultSetting);
            config.load();
            enable = config.getBool(ENABLED_ALL_DOLLY);
        } catch (Exception e){
            EyjafjallaMod.logSomething("Init Config Failed" + e.getLocalizedMessage());
        }
    }

    public static void initModConfigMenu(){
        settingsPanel = new ModPanel();
        addEnableMenu();
        UIStrings uiStrings = CardCrawlGame.languagePack.getUIString(StringHelper.CONFIG);
        String modConfDesc = uiStrings.TEXT[1];
        Texture badge  = ImageMaster.loadImage("EyjafjallaResources/img/orbs/EnergyOrb.png");
        BaseMod.registerModBadge(badge,"eyjafjalla","FimmlpS",modConfDesc,settingsPanel);
    }

    private static void addEnableMenu(){
        UIStrings uiStrings = CardCrawlGame.languagePack.getUIString(StringHelper.CONFIG);
        ModLabeledToggleButton btn = new ModLabeledToggleButton(uiStrings.TEXT[0],350F,650F, Settings.CREAM_COLOR, FontHelper.charDescFont,enable,settingsPanel, modLabel -> {
        },modToggleButton -> {
            enable = modToggleButton.enabled;
            config.setString(ENABLED_ALL_DOLLY, String.valueOf(enable));
            try {
                config.save();
            } catch (IOException e) {
                EyjafjallaMod.logSomething("save config credit failed" + e.getLocalizedMessage());
            }
        });

        settingsPanel.addUIElement(btn);
    }


}
